/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.csm.csmstaffhelper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 *
 * @author exception
 */
public class CsmProperties {
    private String url;

    private StaffLevel baseLevel;

    private String sid;

    private Integer minutes;

    private Boolean stricted;

    private String alarm;

    public CsmProperties() throws IOException {
        File file = new File("csman.properties");
        if(file.exists() == false) {
            url = "http://www.cs-manager.com/csm/?p=office_staff&s=hire&t=3";
            sid = "";
            minutes = 5;
            stricted = true;
            alarm = "scream.wav";
            baseLevel = new StaffLevel(0, 0, 0);

            saveProperties();
        }

        
        Properties properties = new Properties();
        properties.load(new FileInputStream("csman.properties"));

        this.url = properties.getProperty("url");
        this.sid = properties.getProperty("sid");

        Integer level1 = new Integer(properties.getProperty("level1"));
        Integer level2 = new Integer(properties.getProperty("level2"));
        Integer level3 = new Integer(properties.getProperty("level3"));
        this.baseLevel = new StaffLevel(level1, level2, level3);

        this.minutes = new Integer(properties.getProperty("minutes"));
        
        this.stricted = (properties.getProperty("stricted").equals("true") || properties.getProperty("stricted").equals("1"));

        this.alarm = properties.getProperty("alarm");
    }

    public void saveProperties() throws IOException {
        Properties properties = new Properties();

        properties.setProperty("url", url);
        properties.setProperty("sid", sid);
        properties.setProperty("level1", baseLevel.getLevel1().toString());
        properties.setProperty("level2", baseLevel.getLevel2().toString());
        properties.setProperty("level3", baseLevel.getLevel3().toString());
        properties.setProperty("minutes", minutes.toString());
        properties.setProperty("stricted", (stricted == true ? "true" : "false"));
        properties.setProperty("alarm", alarm);

        properties.store(new FileOutputStream("csman.properties"),"");
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @return the baseLevel
     */
    public StaffLevel getBaseLevel() {
        return baseLevel;
    }

    /**
     * @return the sid
     */
    public String getSid() {
        return sid;
    }

    /**
     * @return the minutes
     */
    public Integer getMinutes() {
        return minutes;
    }

    /**
     * @return the stricted
     */
    public Boolean getStricted() {
        return stricted;
    }

    /**
     * @return the alarm
     */
    public String getAlarm() {
        return alarm;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @param baseLevel the baseLevel to set
     */
    public void setBaseLevel(StaffLevel baseLevel) {
        this.baseLevel = baseLevel;
    }

    /**
     * @param sid the sid to set
     */
    public void setSid(String sid) {
        this.sid = sid;
    }

    /**
     * @param minutes the minutes to set
     */
    public void setMinutes(Integer minutes) {
        this.minutes = minutes;
    }

    /**
     * @param stricted the stricted to set
     */
    public void setStricted(Boolean stricted) {
        this.stricted = stricted;
    }

    /**
     * @param alarm the alarm to set
     */
    public void setAlarm(String alarm) {
        this.alarm = alarm;
    }
}
